<template>
    <div class="goods-list">
        <h1 class="c-title">商品列表</h1>
        <table class="c-table" cellspacing="0">
            <thead>
                <tr>
                    <th>商品类型</th>
                    <th>订单总数(单)</th>
                    <th>流水总金额(元)</th>
                    <th>收益总金额(元)</th>
                    <th>公司收益总金额(元)</th>
                    <th>客户收益总金额(元)</th>
                    <th>分配通道</th>
                    <th>编辑价格</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in tableData">
                    <td>{{ item.orderType }}</td>
                    <td>{{ item.orderCount }}</td>
                    <td>{{ item.payAmount }}</td>
                    <td>{{ item.totalProfit }}</td>
                    <td>{{ item.companyProfit }}</td>
                    <td>{{ item.cloudProfit }}</td>
                    <td><router-link class="iconfont icon-bianji" :title="'分配通道(' + item.orderType + ')'" :to="getChannelPath(item.orderType)"></router-link></td>
                    <td><router-link class="iconfont icon-bianji" :title="'编辑价格(' + item.orderType + ')'" :to="getPricePath(item.orderType)"></router-link></td>
                </tr>
            </tbody>
        </table>
        <loading v-if="loading"></loading>
    </div>
</template>

<script>
    import axios from 'axios';
    import Loading from '@/component/loading.vue';
    document.title = '商品列表';
    export default {
        name: 'goodsList',
        data(){
            return {
                loading: false,
                tableData: [],
            };
        },
        created(){
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                axios({
                    method: 'get',
                    url: API_PATH + '/platformOrder/getPlatformGoodStatisticsList',
                    dataType: 'json',
                }).then(
                    res => {
                        this.loading = false;
                        if(res.data.code == 0){
                            this.tableData = res.data.data;
                        }
                    },
                    xhr => {
                        this.loading = false;
                    }
                );
            },
            getChannelPath(name){
                switch (name){
                    case '流量': return '/goods/editFlowChannel';
                    case '话费': return '/goods/editBillChannel';
                    case 'Q币':  return '/goods/editEntChannel/CURRENCY';
                    case '游戏': return '/goods/editEntChannel/GAME';
                    case '视频': return '/goods/editEntChannel/VIDEO';
                    case '音乐': return '/goods/editEntChannel/MUSIC';
                }
                return '';
            },
            getPricePath(name){
                switch (name){
                    case '流量': return '/goods/editFlowPrice';
                    case '话费': return '/goods/editBillPrice';
                    case 'Q币':  return '/goods/editEntPrice/CURRENCY';
                    case '游戏': return '/goods/editEntPrice/GAME';
                    case '视频': return '/goods/editEntPrice/VIDEO';
                    case '音乐': return '/goods/editEntPrice/MUSIC';
                }
                return '';
            },
        },
        components: {
            Loading,
        },
    }
</script>
